<?php
namespace app\common\model;
class Order extends Base
{
    protected $type = [
        'send_time'  =>  'timestamp',
        'pay_time'  =>  'timestamp',
        'close_time' => 'timestamp',
        'refund_time' => 'timestamp',
    ];
    protected function initialize()
    {
        parent::initialize();
    }

    /* 取消超时订单 */
    public static function cancelOrder () {
        $where = [
            'create_time' => [
                'lt',time()-24*3600
            ],
            'checked' => 0
        ];
        $save = [
            'checked' => 6,
            'close_time' => time(),
            'close_reason' => 'system timeout'
        ];
        self::where($where)->update($save);
    }

    /* 超时确认收货 */
    public static function shouhuoOrder () {
        $where = [
            'send_time' => [
                'lt',time()-24*3600*7
            ],
            'checked' => 5
        ];
        $save = [
            'checked' => 2,
            'shouhuo_time' => time(),
        ];
        self::where($where)->update($save);
    }
}